<template>
  <div>
    <RouterLink to="/">返回</RouterLink>
    <h2>添加页面</h2>
    <p><label for="">商品名称：</label><input type="text" v-model="good_name"></p>
    <p><label for="">商品价格：</label><input type="text" v-model="good_price"></p>
    <p><label for="">商品数量：</label><input type="text" v-model="good_count"></p>
    <p><button @click="add">添加</button></p>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { addData } from '../api/RequestApi'
import { RouterLink, useRouter } from 'vue-router'

let good_name = ref('')
let good_price = ref('')
let good_count = ref('')
let router = useRouter()

const add = async () => {
  // 获取提交的数据
  const data = {
    good_name: good_name.value,
    good_price: good_price.value,
    good_count: good_count.value
  }
  let res = await addData(data)
  // console.log(res)
  if (res.code === 200) {
    router.push('/')  // 跳转到首页
  }

}

</script>

<style lang="scss" scoped></style>